package com.dabai.qrtools.other;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.dabai.qrtools.R;

/**
 * Description : Other
 *
 * @author BAI
 */
public class ImageUtils {

    public static Bitmap getTransparentBitmap(Bitmap sourceImg, int number){
        int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];

        sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg

                .getWidth(), sourceImg.getHeight());// 获得图片的ARGB值

        number = number * 255 / 100;

        for (int i = 0; i < argb.length; i++) {

            argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);

        }

        sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg

                .getHeight(), Bitmap.Config.ARGB_8888);

        return sourceImg;
    }

    /**
     * 显示大图片
     *
     * @param context 上下文
     * @param bitmap  位图
     */
    public static void showBigImage(Context context, Bitmap bitmap){

        Dialog dia = new Dialog(context,R.style.bigImageStyle);
        dia.setContentView(R.layout.dialog_image_big);
        ImageView imageView = dia.findViewById(R.id.imageView);
        //可以set任何格式图片
        imageView.setImageBitmap(bitmap);
        dia.show();
        //选择true的话点击其他地方可以使dialog消失，为false的话不会消失
        dia.setCanceledOnTouchOutside(true); // Sets whether this dialog is
        Window w = dia.getWindow();
        WindowManager.LayoutParams lp = w.getAttributes();
        lp.x = 0;
        lp.y = 40;
        dia.onWindowAttributesChanged(lp);

    }

}
